import db from "@src/dataBase/db";
import Sequelize from "sequelize";
import FieldCategory from "@src/models/fieldCategory";

const Dict = db.define("Dict", {
    id: {type: Sequelize.STRING, primaryKey: true},
    type_id: {type: Sequelize.STRING},
    name: {type: Sequelize.STRING},
    created_at: {type: Sequelize.BIGINT},
    updated_at: {type: Sequelize.BIGINT},
}, {
    timestamps: false,
    underscored: true,
    tableName: "dict"
});

// 一对一
Dict.belongsTo(FieldCategory,{
    // 开始key
    foreignKey:"type_id",
    // 目标key
    targetKey:"id"
})

FieldCategory.hasOne(Dict,{
    // 开始key
    foreignKey:"type_id",
    // 来源key
    sourceKey:"id"
})
export default Dict;